package com.kiloai.base.custom;

import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by david on 17/7/3.
 * TextView被点击时透明度设为0.8
 * 点击结束时设为1.0
 */

public class ClickTextView extends AppCompatTextView {

    private final float CLICKED_TRANS = 0.8f;
    private final float UNCLICK_TRANS = 1.0f;

    public ClickTextView(Context context) {
        super(context);
    }

    public ClickTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ClickTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                this.setAlpha(CLICKED_TRANS);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                this.setAlpha(UNCLICK_TRANS);
                break;
        }

        return super.onTouchEvent(event);
    }
}
